package de.stefangoebel.aufgabenplaner;

import java.util.Calendar;

import android.content.Context;
import android.util.Log;

public class Aufgabe {
	private Context context;
	private int id;
	private Calendar date;
	private String name;
	private String category;
	private String priority;
	private int duration;
	
	public Aufgabe(Context context, Calendar date) {
		this.context = context;
		this.id = 0;
		this.date = date;
		this.name = "";
		this.category = "";
		this.priority = "";
		this.duration = 0;
	}
	
	public Aufgabe(Context context, int id, Calendar date, String name, String category, String priority, int duration) {
		this.context = context;
		this.id = id;
		this.date = date;
		this.name = name;
		this.category = category;
		this.priority = priority;
		this.duration = duration;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public Calendar getDate() {
		return date;
	}
	public void setDate(Calendar date) {
		this.date = date;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	
	public String getPriority() {
		return priority;
	}
	public void setPriority(String priority) {
		this.priority = priority;
	}
	
	public int getDuration() {
		return duration;
	}
	public void setDuration(int duration) {
		this.duration = duration;
	}

	public String getCategoryText() {
		return getTitle(R.array.pref_aufgabe_category_titles, R.array.pref_aufgabe_category_values, category);
	}
	public String getPriorityText() {
		return getTitle(R.array.pref_aufgabe_priority_titles, R.array.pref_aufgabe_priority_values, priority);
	}
	public String getDurationText() {
		return getTitle(R.array.pref_aufgabe_duration_titles, R.array.pref_aufgabe_duration_values, String.valueOf(duration));
	}
	
	private String getTitle(int arrayTitles, int arrayValues, String value) {
		String[] titles = context.getResources().getStringArray(arrayTitles);
		String[] values = context.getResources().getStringArray(arrayValues);
		
		for(int i = 0; i < values.length; i++) {
			if (values[i].equals(value)) {
				return titles[i];
			}
		}
		
		return "";
	}
}
